package com.wanqing.community.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.wanqing.community.bean.RoleBean;
import com.wanqing.community.dao.RoleDao;
import com.wanqing.community.dao.util.MyBatisDao;
import com.wanqing.community.util.ConditionParse;

/**
 * 角色管理DAO实现
 * All right reserved.
 * @version 
 */
@Repository("roleDao")
public class RoleDaoImpl extends MyBatisDao<RoleBean, String> implements RoleDao{

	private final String NAMES_SPACE = "com.wanqing.community.bean.RoleBean";

	public int addRole(RoleBean role) {	
		System.out.print(role.getRoleName());
		return this.save(NAMES_SPACE+".addRole", role);
	}
	
	public int deleteRole(List<String> list) {		
		return this.deleteBatchById(NAMES_SPACE+".deleteRole", list);
	}
	
	public int getRoleCount(ConditionParse condParse) {		
		return this.getCount(NAMES_SPACE+".getRoleCount", condParse);
	}
	
	public List<RoleBean> queryRole(ConditionParse condParse, int currPage,
			int pageSize) {	
		
		return this.queryForList(NAMES_SPACE+".queryRolePage", condParse, currPage, pageSize);
	}
	
	public int updateRole(RoleBean role) {		
		return this.update(NAMES_SPACE+".updateRole", role);
	}

	/**
	 * <p>Description：批量添加角色权限<p>
	 * <p>modifiContent:<p>
	 * @param list
	 * @return
	 */
	public int addRoleAuthorBatch(List<Map<String, Object>> list) {		
		return this.saveBatchForMap(NAMES_SPACE+".addRoleAuthorBatch", list);
	}

	/**
	 * 
	 * <p>Description:查询角色对应的权限<p>
	 * <p>modifiContent:<p>
	 * @param roleId
	 * @return
	 */
	public List<RoleBean> queryOperaAuthorRole(String roleId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("roleId", roleId);
		return this.queryForList(NAMES_SPACE+".queryOperaAuthorRole", map);
	}

	/**
	 * 
	 * <p>Description:删除角色对应的功能权限<p>
	 * <p>modifiContent:<p>
	 * @param roleId
	 * @return
	 */
	public int deleteFuncAuthor(String roleId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("roleId", roleId);
		return this.delete(NAMES_SPACE+".deleteAuthorFunc", map);
	}

	/**
	 * 
	 * <p>Description:查询所有的角色信息<p>
	 * <p>modifiContent:<p>
	 * @return
	 */
	public List<RoleBean> listRole() {		
		return this.queryForList(NAMES_SPACE+".listRole");
	}

}
